package com.Cheng.controller;

import com.Cheng.pojo.Income;
import com.Cheng.pojo.Outcome;
import com.Cheng.service.OutcomeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * @Author Cheng
 * @Date 2022/4/10 16:40
 */
@Controller
@RequestMapping("/outcome")
public class OutcomeController {
    @Autowired
    @Qualifier("OutcomeServiceImpl")
    private OutcomeService outcomeService;

    @RequestMapping("/allOutcome")
    public String list(Model model){
        List<Outcome> list = outcomeService.queryAllOutcome();
        model.addAttribute("list", list);
        return "allOutcome";
    }
    @RequestMapping("/allOutcome1")
    public String list1(Model model){
        List<Outcome> list = outcomeService.queryAllOutcome();
        model.addAttribute("list", list);
        return "two4";
    }

    @RequestMapping("/allOutcome2")
    public String list2(Model model){
        List<Outcome> list = outcomeService.queryAllOutcome();
        model.addAttribute("list", list);
        return "two5";
    }

    @RequestMapping("/toAddOutcome")
    public String toAddPaper() {
        return "addOutcome";
    }

    @RequestMapping("/addOutcome")
    public String addPaper(Outcome outcome) {
        System.out.println(outcome);
        outcomeService.addOutcome(outcome);
        return "redirect:/outcome/allOutcome";
    }

    @RequestMapping("/toUpdateOutcome")
    public String toUpdateOutcome(Model model, int id) {
        Outcome outcome = outcomeService.queryOutcomeById(id);
        model.addAttribute("outcome",outcome );
        return "updateOutcome";
    }

    @RequestMapping("/updateOutcome")
    public String updateOutcome(Model model, Outcome outcome) {
        outcomeService.updateOutcome(outcome);
        Outcome outcome1 = outcomeService.queryOutcomeById(outcome.getOutcomeID());
        model.addAttribute("outcome", outcome1);
        return "redirect:/outcome/allOutcome";
    }

    @RequestMapping("/del")
    public String deleteOutcome(int id){
        outcomeService.deleteOutcomeById(id);
        return "redirect:/outcome/allOutcome";
    }
}
